import LanguageMngTs from "../Managers/LanguageMngTs";

cc.Class({
    extends: cc.Component,

    properties: {
        frameNormal:{
            default:null,
            type:cc.SpriteFrame,
        },

        frameSelected:{
            default:null,
            type:cc.SpriteFrame
        },

        buttonParent:{
            default:null,
            type:cc.Node
        },

        contentParent:{
            default:null,
            type:cc.Node
        },

        contentTitle:{
            default:null,
            type:cc.Label
        },

        
        langlabel1:{
            default:null,
            type:cc.Label
        },

        langlabel2:{
            default:null,
            type:cc.Label
        },

        langlabel3:{
            default:null,
            type:cc.Label
        },

        langlabel4:{
            default:null,
            type:cc.Label
        },

        langlabel5:{
            default:null,
            type:cc.Label
        }
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this.showContentByName("rummy_basics")
        cc.gg.tdUtil.doSendTdPageStart("HelpPage")
        this.lang()
    },
    
    lang(){
        this.langlabel1.string = LanguageMngTs.getSentence(282) + "\n" + LanguageMngTs.getSentence(283) + "\n" + LanguageMngTs.getSentence(284);
        this.langlabel2.string = LanguageMngTs.getSentence(286) + "\n" + LanguageMngTs.getSentence(287) ;
        this.langlabel3.string = LanguageMngTs.getSentence(298) + "\n" + LanguageMngTs.getSentence(299) ;
        this.langlabel4.string = LanguageMngTs.getSentence(330) + "\n" + LanguageMngTs.getSentence(331) ;
        this.langlabel5.string = LanguageMngTs.getSentence(334) + "\n" + LanguageMngTs.getSentence(335) + "\n" + LanguageMngTs.getSentence(336);
    },

    setMoreHelpCloseFunc:function (cb) {
        this.closeFunc = cb
    },

    // update (dt) {},

    showContentByName:function (name) {
        for(let i=0;i<this.buttonParent.children.length;i++){
            let node = this.buttonParent.children[i]
            if(node.name === name){
                cc.find("help_btn_normal",node).getComponent(cc.Sprite).spriteFrame = this.frameSelected
                this.showOnlyOneContentNode(name)
                this._changeTitle(name)
            }else {
                cc.find("help_btn_normal",node).getComponent(cc.Sprite).spriteFrame = this.frameNormal
            }
        }
    },

    onMoreHelpTabsClicked:function (event) {
        let btnName = event.target.name
        this.showContentByName(btnName)
    },

    showOnlyOneContentNode:function (name) {
        let nodes = this.contentParent.children
        for(let i=0;i<nodes.length;i++){
            let node = nodes[i]
            if(node.name === name){
                node.active = true
            }else {
                node.active = false
            }
        }
    },

    _changeTitle:function (btnName) {
        if(btnName === "rummy_basics"){
            this.contentTitle.string = LanguageMngTs.getSentence(153);  // "RUMMY BASICS"
        }else if(btnName === "sequence"){
            this.contentTitle.string = LanguageMngTs.getSentence(271); // "SEQUENCES"
        }else if(btnName === "sets"){
            this.contentTitle.string = LanguageMngTs.getSentence(272); // "SETS"
        }else if(btnName === "group"){
            this.contentTitle.string = LanguageMngTs.getSentence(273); //  "HOW TO GROUP?"
        }else if(btnName === "add"){
            this.contentTitle.string = LanguageMngTs.getSentence(274); //  "HOW TO ADD?"
        }else if(btnName === "discard"){
            this.contentTitle.string = LanguageMngTs.getSentence(275); //  "HOW TO DISCARD?"
        }else if(btnName === "score"){
            this.contentTitle.string = LanguageMngTs.getSentence(146); //  "SCORE"
        }else if(btnName === "declare"){
            this.contentTitle.string = LanguageMngTs.getSentence(276); // "HOW TO DECLARE?"
        }
    },

    onMoreHelpClosed:function (evnet) {
        if(this.closeFunc){
            this.closeFunc()
            return
        }
        // this.node.destroy()
        cc.find("Canvas/UIManager").emit("ui_show_more_help")


        cc.gg.tdUtil.doSendTdPageEnd("HelpPage")
    },
});
